home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Part.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  7.5 KB  |  276 lines

  1. package
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    import flash.geom.*;
  6.    
  7.    public class Part extends Bitmap
  8.    {
  9.        
  10.       
  11.       internal var _partTuckIn:Part = null;
  12.       
  13.       internal var _sPose:String;
  14.       
  15.       internal var _bFront:Bitmap = null;
  16.       
  17.       internal var _parttemplate:PartTemplate;
  18.       
  19.       internal var _bBack:Bitmap = null;
  20.       
  21.       public function Part()
  22.       {
  23.          _bFront = null;
  24.          _bBack = null;
  25.          _partTuckIn = null;
  26.          super();
  27.          addEventListener(Event.ADDED_TO_STAGE,onAdded,false,0,true);
  28.          addEventListener(Event.REMOVED_FROM_STAGE,onRemoved,false,0,true);
  29.       }
  30.       
  31.       public function center() : void
  32.       {
  33.          x = -width / 2;
  34.          y = -height / 2;
  35.       }
  36.       
  37.       protected function onRemoved(param1:Event) : void
  38.       {
  39.          if(_bFront != null)
  40.          {
  41.             _bFront.parent.removeChild(_bFront);
  42.             _bFront = null;
  43.          }
  44.          if(_bBack != null)
  45.          {
  46.             _bBack.parent.removeChild(_bBack);
  47.             _bBack = null;
  48.          }
  49.          if(_partTuckIn != null)
  50.          {
  51.             _partTuckIn.parent.removeChild(_partTuckIn);
  52.             _partTuckIn = null;
  53.             alpha = 1;
  54.          }
  55.       }
  56.       
  57.       protected function onAdded(param1:Event) : void
  58.       {
  59.          var _loc2_:Model = null;
  60.          var _loc3_:MovieClip = null;
  61.          var _loc4_:PartTemplate = null;
  62.          if(parent.parent is Model)
  63.          {
  64.             _loc2_ = parent.parent as Model;
  65.             if(Template.HasFront)
  66.             {
  67.                if(_bFront == null)
  68.                {
  69.                   _bFront = new Bitmap();
  70.                   _loc3_ = _loc2_.getLayers()[Model.NUM_LAYERS - 2] as MovieClip;
  71.                   _loc3_.addChild(_bFront);
  72.                   adjust(_bFront);
  73.                }
  74.             }
  75.             if(Template.HasBack)
  76.             {
  77.                if(_bBack == null)
  78.                {
  79.                   _bBack = new Bitmap();
  80.                   _loc3_ = _loc2_.getLayers()[1] as MovieClip;
  81.                   _loc3_.addChild(_bBack);
  82.                   adjust(_bBack);
  83.                }
  84.             }
  85.             if((_loc4_ = getTuckInTemplate()) != null)
  86.             {
  87.                _partTuckIn = _loc4_.createPart();
  88.                _loc3_ = _loc2_.getLayers()[this.Layer] as MovieClip;
  89.                _loc3_.addChild(_partTuckIn);
  90.                _partTuckIn.x = 0;
  91.                _partTuckIn.y = 0;
  92.                _partTuckIn.alpha = 0;
  93.             }
  94.             Pose = Pose;
  95.          }
  96.       }
  97.       
  98.       public function get Template() : PartTemplate
  99.       {
  100.          return _parttemplate;
  101.       }
  102.       
  103.       public function hasPixel(param1:Number, param2:Number, param3:DisplayObjectContainer) : Boolean
  104.       {
  105.          var _loc4_:Boolean = false;
  106.          var _loc5_:Rectangle = null;
  107.          var _loc6_:int = 0;
  108.          _loc4_ = false;
  109.          if((_loc5_ = getBounds(param3)).containsPoint(new Point(param1,param2)))
  110.          {
  111.             if((_loc6_ = int(bitmapData.getPixel32(param1 - _loc5_.x,param2 - _loc5_.y))) != 0)
  112.             {
  113.                _loc4_ = true;
  114.             }
  115.             else if(_bBack != null)
  116.             {
  117.                if((_loc6_ = int(_bBack.bitmapData.getPixel32(param1 - _loc5_.x,param2 - _loc5_.y))) != 0)
  118.                {
  119.                   _loc4_ = true;
  120.                }
  121.             }
  122.          }
  123.          return _loc4_;
  124.       }
  125.       
  126.       public function get Category() : String
  127.       {
  128.          return _parttemplate.Category;
  129.       }
  130.       
  131.       public function set Template(param1:PartTemplate) : *
  132.       {
  133.          _parttemplate = param1;
  134.          Pose = ModelPose.DEFAULT;
  135.       }
  136.       
  137.       public function get Layer() : int
  138.       {
  139.          return _parttemplate.Layer;
  140.       }
  141.       
  142.       public function isEqual(param1:Part) : Boolean
  143.       {
  144.          if(param1 != null)
  145.          {
  146.             if(Template.Name == param1.Template.Name)
  147.             {
  148.                return true;
  149.             }
  150.          }
  151.          return false;
  152.       }
  153.       
  154.       protected function getTuckInTemplate() : PartTemplate
  155.       {
  156.          var _loc1_:* = null;
  157.          _loc1_ = Template.Name + "_VER2";
  158.          return MainDocument.Package.getTemplateByName(_loc1_);
  159.       }
  160.       
  161.       protected function adjust(param1:DisplayObject) : void
  162.       {
  163.          var _loc2_:int = 0;
  164.          _loc2_ = ModelPose.poseToIndex(_sPose,Template.Category);
  165.          param1.x = Template.PoseAdjustments[_loc2_].x;
  166.          param1.y = Template.PoseAdjustments[_loc2_].y;
  167.       }
  168.       
  169.       public function get Pose() : String
  170.       {
  171.          return _sPose;
  172.       }
  173.       
  174.       public function updateTuckIn() : void
  175.       {
  176.          var _loc1_:Model = null;
  177.          var _loc2_:Part = null;
  178.          if(_partTuckIn != null)
  179.          {
  180.             if(parent != null)
  181.             {
  182.                _loc1_ = parent.parent as Model;
  183.                if(_loc1_ != null)
  184.                {
  185.                   _loc2_ = null;
  186.                   switch(Category)
  187.                   {
  188.                      case "top":
  189.                         _loc2_ = _loc1_.getPart("bottom");
  190.                         break;
  191.                      case "bottom":
  192.                         _loc2_ = _loc1_.getPart("top");
  193.                   }
  194.                   if(_loc2_ != null && _loc2_.Layer > Layer)
  195.                   {
  196.                      _partTuckIn.alpha = 1;
  197.                      alpha = 0;
  198.                   }
  199.                   else
  200.                   {
  201.                      _partTuckIn.alpha = 0;
  202.                      alpha = 1;
  203.                   }
  204.                }
  205.                else
  206.                {
  207.                   _partTuckIn.alpha = 0;
  208.                   alpha = 1;
  209.                }
  210.             }
  211.             else
  212.             {
  213.                _partTuckIn.alpha = 0;
  214.                alpha = 1;
  215.             }
  216.          }
  217.       }
  218.       
  219.       public function ResizePart(param1:Number) : void
  220.       {
  221.          if(width > height)
  222.          {
  223.             if(width > param1)
  224.             {
  225.                height = param1 * height / width;
  226.                width = param1;
  227.             }
  228.          }
  229.          else if(height > param1)
  230.          {
  231.             width = param1 * width / height;
  232.             height = param1;
  233.          }
  234.       }
  235.       
  236.       public function set Pose(param1:String) : *
  237.       {
  238.          _sPose = param1;
  239.          this.bitmapData = _parttemplate.getBitmapData(_sPose);
  240.          if(Template.DefaultBitmapProvided && _sPose == ModelPose.DEFAULT)
  241.          {
  242.             x = 0;
  243.             y = 0;
  244.             if(_bFront != null)
  245.             {
  246.                _bFront.visible = false;
  247.             }
  248.             if(_bBack != null)
  249.             {
  250.                _bBack.visible = false;
  251.             }
  252.          }
  253.          else
  254.          {
  255.             adjust(this);
  256.             if(_bFront != null)
  257.             {
  258.                _bFront.bitmapData = _parttemplate.getBitmapDataFront(_sPose);
  259.                _bFront.visible = true;
  260.                adjust(_bFront);
  261.             }
  262.             if(_bBack != null)
  263.             {
  264.                _bBack.bitmapData = _parttemplate.getBitmapDataBack(_sPose);
  265.                _bBack.visible = true;
  266.                adjust(_bBack);
  267.             }
  268.          }
  269.          if(_partTuckIn != null)
  270.          {
  271.             _partTuckIn.Pose = Pose;
  272.          }
  273.       }
  274.    }
  275. }
  276.